﻿Imports Aricie.DNN.Services.Url.FriendlyUrl
Imports Aricie.DNN.Diagnostics
Imports System.Linq

Namespace Aricie.DNN.Services.Url.FriendlyUrl

    Public Class LoggingEntry
        Public Property Key As String
        Public Property Value As String

        Public Sub New(_k As String, _v As String)
            Key = _k
            Value = _v
        End Sub

        Public Function ToKeyValuePair() As KeyValuePair(Of String, String)
            Return New KeyValuePair(Of String, String)(Key, Value)
        End Function

    End Class

    Public Class LoggingHelper

        Public Shared Sub LogStart(CurrentStep As String, flowId As String, informations As LoggingEntry())
            If (FriendlierUrlContext.LogRequestTiming) Then
                PerformanceLogger.Instance.AddDebugInfo(New StepInfo(Debug.RequestTiming, CurrentStep, WorkingPhase.InProgress, False, False, -1, flowId, informations.Select(Function(le) le.ToKeyValuePair()).ToArray()) With {.Cumulated = Not FriendlierUrlConfig.Instance.LogAnEventPerUrl})
            End If
        End Sub

        Public Shared Sub LogEnd(CurrentStep As String, flowId As String, informations As LoggingEntry())
            If (FriendlierUrlContext.LogRequestTiming) Then
                PerformanceLogger.Instance.AddDebugInfo(New StepInfo(Debug.RequestTiming, CurrentStep, WorkingPhase.EndOverhead, False, False, -1, flowId, informations.Select(Function(le) le.ToKeyValuePair()).ToArray()) With {.Cumulated = Not FriendlierUrlConfig.Instance.LogAnEventPerUrl})
            End If
        End Sub

    End Class

End Namespace